//
//  RW_AgreementCollectionViewCell.m
//  SleepApp
//
//  Created by MAC on 2021/4/10.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_AgreementCollectionViewCell.h"
#import "RW_WebViewController.h"

@interface RW_AgreementCollectionViewCell (){
    RW_AgreementCollectionViewCellModel *_model;
}
@property (nonatomic,strong) UIButton *wlcalss_select_button;
@property (nonatomic,strong) UIButton *wlcalss_title_button;
@end
@implementation RW_AgreementCollectionViewCell

-(void)bind_row_data:(WLBaseCollectionViewLayerRow *)sender{
    if ([sender.data isKindOfClass:RW_AgreementCollectionViewCellModel.class]){
        _model = sender.data;
        
        switch (_model.item_type) {
            case Agreement_Item_Type_Register:
                [self.wlcalss_title_button setTitle:@"《用户协议》" forState:UIControlStateNormal];
                break;
            default:
                break;
        }
        [self change_select_status];
    }
}
-(void)bind_delegate:(id)sender{
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.clearColor;
        [self addSubview:self.wlcalss_title_button];
        [self addSubview:self.wlcalss_select_button];
        [self.wlcalss_select_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(self).mas_offset(0);
        }];
        [self.wlcalss_title_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(self.wlcalss_select_button.mas_right).mas_offset(5);
        }];
    }
    return self;
}

#pragma mark -- 代理
-(void)click_push_agreement:(UIButton *)sender{
    [RW_WebViewController pushProtocolFromVc:[self viewController_wl]];
}
-(void)click_select_agreement:(UIButton *)sender{
    _model.isSelect = !_model.isSelect;
    [self change_select_status];
}

-(void)change_select_status{
    if (_model.isSelect){
        [self.wlcalss_select_button setImage:[UIImage svgName:@"login_agreement_select"] forState:UIControlStateNormal];
    } else {
        [self.wlcalss_select_button setImage:[UIImage svgName:@"login_agreement_not_select"] forState:UIControlStateNormal];
    }
}
#pragma mark -- 懒加载
-(UIButton *)wlcalss_title_button{
    if (!_wlcalss_title_button){
        _wlcalss_title_button = [[UIButton alloc]init];
        [_wlcalss_title_button setTitleColor:HexColor(@"5564BE") forState:UIControlStateNormal];
        _wlcalss_title_button.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
        [_wlcalss_title_button addTarget:self action:@selector(click_push_agreement:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _wlcalss_title_button;
}
-(UIButton *)wlcalss_select_button{
    if (!_wlcalss_select_button){
        _wlcalss_select_button = [[UIButton alloc]init];
        [_wlcalss_select_button addTarget:self action:@selector(click_select_agreement:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _wlcalss_select_button;
    
}
@end

@implementation RW_AgreementCollectionViewCellModel

@end
